package com.action.Interceptor;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;

import com.entity.User;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

public class AuthorityInterceptor extends MethodFilterInterceptor {

	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		ActionContext act = invocation.getInvocationContext();
		HttpServletRequest request = ServletActionContext.getRequest();

		User user = (User) request.getSession().getAttribute("user");
		
		if(user != null) {
			return invocation.invoke();
		} else {
			System.out.println("to logn ...");
			return Action.LOGIN;
		}
//		return invocation.invoke();
	}


}
